-- damage
-- create by weism
-- 攻击受创（技能规则）

return {
    apply = function(source, target, skillId, round, para, extra)
        --威力
        local force = para[1];
        local damage = 0;
        local baseAttack = InterfaceM.calcBaseAttrib(source, "attack");
        if para[2] and target:isBoss() then
            damage = math.modf(baseAttack * force / 2000);
        else
            damage = math.modf(baseAttack * force / 1000);
        end

        -- 增加伤害
        local prop = PropM.combine(source, "equip_damage", skillId);
        damage = PropM.apply(prop, damage);

        -- 增加命中动作,伤害保个底
        damage = math.max(1,damage);

        local addon = 0;
        local args  = {["value"] = damage, ["class_id"] = extra.propertyId,};

        -- 概率造成额外的百分比伤害
        local props = PropM.fetchProps(source, "prob_per_damage");
        for _, prop in ipairs(props) do
            addon = addon + PropM.trigger(source, prop[1], prop[2], args);
        end

        damage = damage + addon;

        -- 修正伤害值（需求是道具伤害，是否被免疫）
        damage = PropertyM.fixPropertyDamage(source, target, para[3], damage);
        SkillM.getSequence(target):hit(source, target, skillId);
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 如果是玩家，抛出攻击结果事件
        if source.type == OBJECT_TYPE_USER then
            EventMgr.fire(event.HERO_ATTACK_RESULT, { ["damage"] = damage, ["extra"] = extra});
        end

        -- 如果受攻击对象是怪物，且由道具触发技能，抛出投掷类攻击事件
        if target.type == OBJECT_TYPE_MONSTER and para[3] > 0 then
            EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = para[3], ["target"] = target, ["source"] = source});
        end

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]) or -1,};
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
};
